/************************************************************************/
// Copyright (C) 2016, han_gangbiao. All rights reserved.
// Use of this source code is governed by a GPL-v2 license that can be found in the License file.
// 
// [Time]:      2016-1-4 21:53:17
// [Author]:    han_gangbiao [http://my.oschina.net/jackhen]
// [Info]:      
/************************************************************************/

#include "net_reactor.h"
#include "net_inside/net_reactor_impl.h"

net_reactor_t::net_reactor_t()
	:m_impl(0)
{
	m_impl = new net_reactor_impl_t();
}

net_reactor_t::~net_reactor_t()
{
	SAFE_DELETE(m_impl);
}

int net_reactor_t::init_reactor( IEvent_handler* pHandler, int threadnum /*= 4*/ )
{
	if(m_impl)
		return m_impl->init_reactor(pHandler, threadnum);
	return -1;
}

int net_reactor_t::uninit_reactor()
{
	if(m_impl)
		return m_impl->uninit_reactor();
	return -1;
}

SOCK_FD net_reactor_t::open_tcp_server( const char* local_ip, int local_port )
{
	if(m_impl)
		return m_impl->open_tcp_server(local_ip, local_port);
	return -1;
}

SOCK_FD net_reactor_t::open_tcp_client( const char* remote_ip, int remote_port )
{
	if(m_impl)
		return m_impl->open_tcp_client(remote_ip, remote_port);
	return -1;
}
SOCK_FD net_reactor_t::open_udp_endpoint( const char* local_ip, int local_port )
{
	if(m_impl)
		return m_impl->open_udp_endpoint(local_ip, local_port);
	return -1;
}

int net_reactor_t::send( SOCK_FD fd, const char* data, int len )
{
	if(m_impl)
		return m_impl->send(fd, data, len);
	return -1;
}

int net_reactor_t::sendto( SOCK_FD fd, const char* data, int len, const char* remote_ip, int remote_port )
{
	if(m_impl)
		return m_impl->sendto(fd, data, len, remote_ip, remote_port);
	return -1;
}

int net_reactor_t::close_fd( SOCK_FD fd )
{
	if(m_impl)
		return m_impl->close_fd(fd);
	return -1;
}


